 <cfscript>    
    view = createObject("component", "views.layout");   
    view.init("Welcome to E-PAR!","","","Employee Search",main);
    view.html();    
</cfscript>

<cffunction name="main" access="public" output="true" returntype="any">
    <cfparam name="FORM.SearchString" default="">
    <cfset session.SearchString = FORM.SearchString />
    <cfscript>
        import models.*;
        EparEmployees = ORMExecuteQuery("FROM Employee WHERE FirstName LIKE '%" & FORM.SearchString & "%' OR LastName LIKE '%" & FORM.SearchString & "%'");
    </cfscript>
    <cfoutput>
    <h1 class="title">Employee Search</h1>
    <div class="entry">
        <table width="100%" cellpadding="1" cellspacing="2">
            <tbody>
                <tr>
                    <td><strong>Name</strong></td>
                    <td><strong>Start Date</strong></td>                    
                    <td><strong>Hire Step</strong></td>
                    <td><strong>NonSCF Type</strong></td>
                </tr>
            </tbody>
            <cfloop from="1" to="#ArrayLen(EparEmployees)#" index="i" >
                <cfscript>
                    EparEmployeesSteps = ORMExecuteQuery("FROM StepActions WHERE EmployeeID = #EparEmployees[i].getEmployeeID()# AND ActTimeStamp IS NULL AND TermReqID IS NULL");                    
                </cfscript>
                <tbody>
                    <tr>
                        <td><a href="/#session.rootDir#/employeedata.cfm?EmployeeID=#EparEmployees[i].getEmployeeID()#">#EparEmployees[i].getFullName()#</a></td>
                        <td>#DateFormat(EparEmployees[i].getEstStartDate(), 'mm/dd/yyyy')#</td>
                        <td>
                            <cfif ArrayLen(EparEmployeesSteps) gt 0>
                                <cfloop from="1" to="#ArrayLen(EparEmployeesSteps)#" index="ii">
                                    <cfscript>
                                        Step = ORMExecuteQuery("FROM Steps WHERE StepsID = #EparEmployeesSteps[ii].getStepsID()#");
                                        x = "/#session.rootDir#/#Step[1].getController()#?StepID=#EparEmployeesSteps[ii].getStepActionsID()#";
                                        if( EparEmployees[i].getNonSCFTypeID() EQ "" ){
                                            page = "/#session.rootDir#/NonSCF/#Step[1].getController()#?StepID=#EparEmployeesSteps[ii].getStepActionsID()#";
                                        }else{
                                            page = "/#session.rootDir#/SCF/#Step[1].getController()#?StepID=#EparEmployeesSteps[ii].getStepActionsID()#";
                                        }
                                    </cfscript>
                                    <a href="#page#">
                                        #Step[1].getStepDesc()# - #EparEmployeesSteps[ii].getStepActionsID()#
                                    </a>
                                </cfloop>
                            <cfelse>
                                N/A
                            </cfif>
                        </td>
                        <td>
                            <cfscript>                                
                                if( EparEmployees[i].getNonSCFTypeID() EQ "" ){
                                    writeOutput("SCF Employee");
                                }else{
                                    NonSCFTypes = ORMExecuteQuery("FROM NonSCFTypes WHERE NonSCFTypeID = #EparEmployees[i].getNonSCFTypeID()#");
                                    writeOutput(NonSCFTypes[1].getNonSCFType());
                                }
                            </cfscript>
                        </td>
                    </tr>
                </tbody>
            </cfloop>
        </table>
        
    </div>
    </cfoutput>
</cffunction>


